home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / libsrc / c / sys / mntent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-24  |  3.0 KB  |  126 lines

  1. /*
  2.   (c) Copyright 1992 Eric Backus
  3.  
  4.   This software may be used freely so long as this copyright notice is
  5.   left intact.  There is no warrantee on this software.
  6. */
  7.  
  8. #include <dir.h>        /* For findfirst() */
  9. #include <mntent.h>        /* For struct mntent, etc. */
  10.  
  11. /* From fixpath.c */
  12. extern int    _get_default_drive(void);
  13.  
  14. static char        mnt_count = 0;
  15. static struct mntent    mntent;
  16. static struct ffblk    mnt_ff;
  17. static char        drive_string[7];
  18.  
  19. /* These functions are being implemented so that we can compile and
  20.    use the GNU df program.  This program gets the list of mounted
  21.    filesystems, and then summarizes the disk space available on each
  22.    one.
  23.  
  24.    To be complete, the getmntent() function should return all possible
  25.    drives from A to the system's lastdrive parameter.  For each one,
  26.    it should return the volume name.  However, this doesn't turn out
  27.    to work well for floppy disks, because we'll get the ever-popular
  28.    "Abort, Retry, Fail?" prompt when trying to read the volume name
  29.    from a non-existant disk.
  30.  
  31.    As a compromise, the getmntent() function has been made to return
  32.    the 'A' or 'B' drive only if they are the current drive.  This
  33.    works okay, but it means that you must explicitly change to a
  34.    floppy disk before you can df it, which is kind of bogus. */
  35.  
  36. /*ARGSUSED*/
  37. FILE *
  38. setmntent(char *filename, char *type)
  39. {
  40.     mnt_count = 1;
  41.     return (FILE *) 1;
  42. }
  43.  
  44. struct mntent *
  45. getmntent(FILE *filep)
  46. {
  47.     int            drive_number;
  48.     char        *p, *q;
  49.  
  50.     if (mnt_count == 0) return NULL;
  51.     if (mnt_count > 26) return NULL;
  52.  
  53.     if (mnt_count == 1)
  54.     {
  55.     drive_number = _get_default_drive();
  56.  
  57.     switch (drive_number)
  58.     {
  59.     case 0:
  60.         mnt_count = 1;    /* 'A' drive */
  61.         break;
  62.     case 1:
  63.         mnt_count = 2;    /* 'B' drive */
  64.         break;
  65.     default:
  66.         mnt_count = 3;    /* 'C' drive */
  67.         break;
  68.     }
  69.     }
  70.  
  71.     /* Add '*.*' to end for findfirst */
  72.     (void) sprintf(drive_string, "%c:/*.*", 'a' + mnt_count - 1);
  73.  
  74.     /* Get the volume name.  If this fails, the drive is probably not
  75.        a valid drive */
  76.     if (findfirst(drive_string, &mnt_ff, FA_LABEL) != 0)
  77.     return NULL;
  78.  
  79.     /* Strip out extraneous '.' separator */
  80.     if (strlen(mnt_ff.ff_name) > 8 && mnt_ff.ff_name[8] == '.')
  81.     {
  82.     /* Overlapping copy, don't use strcpy() */
  83.     p = &mnt_ff.ff_name[8];
  84.     q = p + 1;
  85.     while ((*p++ = *q++) != '\0');
  86.     }
  87.  
  88.     /* Remove the '*.*' from the drive string for use as mnt_dir */
  89.     drive_string[3] = '\0';
  90.  
  91.     mntent.mnt_fsname = mnt_ff.ff_name;
  92.     mntent.mnt_dir = drive_string;
  93.     mntent.mnt_type = "dos";
  94.     mntent.mnt_opts = "rw";
  95.     mntent.mnt_freq = -1;
  96.     mntent.mnt_passno = -1;
  97.     mntent.mnt_time = -1;
  98.  
  99.     /* Increment drive number.  Skip up to 'C' drive */
  100.     if (mnt_count < 3)
  101.     mnt_count = 3;
  102.     else
  103.     mnt_count++;
  104.  
  105.     return &mntent;
  106. }
  107.  
  108. /*ARGSUSED*/
  109. int addmntent(FILE *filep, struct mntent *mnt)
  110. {
  111.     return 1;
  112. }
  113.  
  114. /*ARGSUSED*/
  115. char *hasmntopt(struct mntent *mnt, char *opt)
  116. {
  117.     return NULL;
  118. }
  119.  
  120. /*ARGSUSED*/
  121. int endmntent(FILE *filep)
  122. {
  123.     mnt_count = 0;
  124.     return 1;
  125. }
  126.